import storage from '@/utils/storage'

const app = {
  state: {
    sidebar: {
      opened: !+storage.get('sidebarStatus')
    },
    // currentMenu: null
    currentMenu: {}
  },
  getters: {
    sidebar: state => state.sidebar,
    currentMenu: state => state.currentMenu
  },
  mutations: {
    TOGGLE_SIDEBAR: state => {
      if (state.sidebar.opened) {
        storage.set('sidebarStatus', 1)
      } else {
        storage.set('sidebarStatus', 0)
      }
      state.sidebar.opened = !state.sidebar.opened
    },
    SET_CURRENT_MENU: (state, currentMenu) => {
      state.currentMenu = currentMenu
    }
  },
  actions: {
    ToggleSideBar: ({ commit }) => {
      commit('TOGGLE_SIDEBAR')
    }
  }
}

export default app
